/*
 * DeleteFileAction.java
 *
 * Created on 13 czerwiec 2007, 18:54
 *
 */

package arocms.upload;

import arocms.business.FileDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author arek
 */
public class DeleteFileAction extends Action {
    
    private final static String SUCCESS = "success";
    private static final String FAILURE = "failure";
    
    private Logger log = Logger.getLogger(this.getClass());
    
    /** Creates a new instance of DeleteFileAction */
    public DeleteFileAction() {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id = request.getParameter("id");
        try {
            Long pk = Long.parseLong(id);
            new FileDAO().delete(pk);
            log.debug("File removed");
            return mapping.findForward(SUCCESS);
        } catch (NumberFormatException ex) {
            log.error(ex.toString());
            return mapping.findForward(FAILURE);
        }
    }
}
